<template>
  <a-modal
    :title="title"
    :width="1000"
    :maskClosable="false"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleCancel"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-card type="inner" title="患者基础情况">
        <detail-list >
          <detail-list-item term="科别" v-if="Detail">{{ Detail.dept }}</detail-list-item>
          <detail-list-item term="主管医生" v-if="Detail">{{ Detail.doc }}</detail-list-item>
          <detail-list-item term="主刀医生" v-if="Detail">{{ Detail.chiefSurgeon }}</detail-list-item>
          <detail-list-item term="病例号" v-if="Detail">{{ Detail.outpatientid }}</detail-list-item>
          <detail-list-item term="年龄" v-if="Detail">{{ Detail.age }}</detail-list-item>
          <detail-list-item term="体重" v-if="Detail">{{ Detail.weight }}</detail-list-item>
          <detail-list-item term="性别" v-if="Detail">{{ Detail.sex === '1' ? '男' : '女' }}</detail-list-item>
          <detail-list-item term="出入院时间" v-if="Detail">{{ Detail.inTime}}--{{ Detail.outTime}}</detail-list-item>
          <detail-list-item term="出院诊断" v-if="Detail">{{ Detail.diagnosis}}</detail-list-item>
        </detail-list>
      </a-card>

      <a-card type="inner" title="手术情况">
        <detail-list>
          <detail-list-item term="手术名称" v-if="Detail">{{ Detail.operation }}</detail-list-item>
          <detail-list-item term="手术日期" v-if="Detail">{{ Detail.operationDate }}</detail-list-item>
          <detail-list-item term="切口类型" v-if="Detail">{{ Detail.incisionType }}</detail-list-item>
          <detail-list-item term="切口愈合" v-if="Detail">{{ Detail.incisionHeal }}</detail-list-item>
          <detail-list-item term="手术开始时间" v-if="Detail">{{ Detail.startTime }}</detail-list-item>
          <detail-list-item term="手术结束时间" v-if="Detail">{{ Detail.endTime }}</detail-list-item>
          <detail-list-item term="手术持续时间" v-if="Detail">{{ Detail.duration}}</detail-list-item>
          <detail-list-item term="术前用药时机" v-if="Detail">{{ Detail.opportunity}}</detail-list-item>
          <detail-list-item term="术中追加" v-if="Detail">{{ Detail.add ? '是' : '否'}}</detail-list-item>
        </detail-list>
        <div class="title">用药情况</div>
        <a-table
          style="margin-bottom: 24px"
          :columns="goodsColumns"
          :dataSource="loadGoodsData"
          :pagination="false">
        </a-table>
      </a-card>
    </a-spin>
  </a-modal>
</template>

<script>
import { getAction1, postActionparams1,postActionparams2, getAction2, getAction, postAction } from '@/api/manage'
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item

export default {
  name: 'operationDetailModel',
  components: {
    DetailList,
    DetailListItem
  },

  data() {
    return {
      title: '围手术期抗菌药物临床应用监测记录表',
      visible: false,
      formData: {},
      model: {},
      noTitleKey: '1',
      tabListNoTitle: [
        {
          key: '1',
          tab: '初评'
        },
        {
          key: '2',
          tab: '科室内评审'
        },
        {
          key: '3',
          tab: '点评会'
        }
      ],
      layout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 14 }
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      Detail:{},
      loadGoodsData:[],
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      goodsColumns: [
        {
          title: '通用名',
          dataIndex: 'drug',
          key: 'drug'
        },
        {
          title: '途径',
          dataIndex: 'route',
          key: 'route'
        },
        {
          title: '剂量',
          dataIndex: 'dosage',
          customRender:function(t, r, index) {
             return r.dosage + r.unit
          }
        },
        {
          title: '溶媒',
          dataIndex: 'menstruum',
          key: 'menstruum',
        },
        {
          title: '频次',
          dataIndex: 'frequency',
          key: 'frequency'
        },
        {
          title: '用药目的',
          dataIndex: 'objective',
          key: 'objective',
        },
      ],
      url: {
        add: '/test/jeecgDemo/add',
        edit: '/test/jeecgDemo/edit',
        detail: '/test/jeecgDemo/edit'
      }
    }
  },
  created() {},
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    detail(record) {
      this.model = Object.assign({}, record)
      this.Detail = this.model
      this.visible = true
      this.getDetail();
    },
    close() {
      //   this.$refs.form.resetFields()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      console.log("11111111111111111111")
      console.log(this.Detail.id)
      this.$refs.a1.add(this.Detail.id)
      //   const that = this
      //   // 触发表单验证
      //   this.$refs.form.validate(valid => {
      //     if (valid) {
      //       that.confirmLoading = true
      //       let httpurl = ''
      //       let method = ''
      //       if (!this.model.id) {
      //         httpurl += this.url.add
      //         method = 'post'
      //       } else {
      //         httpurl += this.url.edit
      //         method = 'put'
      //       }
      //       httpAction(httpurl, this.model, method)
      //         .then(res => {
      //           if (res.success) {
      //             that.$message.success(res.message)
      //             that.$emit('ok')
      //           } else {
      //             that.$message.warning(res.message)
      //           }
      //         })
      //         .finally(() => {
      //           that.confirmLoading = false
      //           that.close()
      //         })
      //     }
      //   })
      this.ModalText = '提交审核中'
      this.confirmLoading = true
      setTimeout(() => {
        this.visible = false
        this.confirmLoading = false
      }, 2000)
    },
    handleTabChange (key, type) {
      this[type] = key
    },
    getDetail() {
      let that = this
      var param = {
        id : this.model.id
        // pageNo: that.ipagination.current,
        // pageSize: that.ipagination.pageSize,
      }
      postActionparams2('/perioperative/getDetail', param)
        .then((res) => {
          console.log(res)
          if (res.code == 0) {
            //that.Detail = res.result

            that.loadGoodsData = this.getDruglist(res.result)
            that.Detail.incisionHeal = this.getIncisionHeal()
            that.Detail.incisionType = this.getIncisionType()
            that.Detail.opportunity = this.getOpportunity()
          }
        })
    },
    getDruglist(list) {
      var newlist =[]
      for(let item of list ){
        if (item.objective == '0') {
          item.objective = '预防'
        }
        if (item.objective  == '1') {
          item.objective = '治疗'
        }
        if (item.objective  == '2') {
          item.objective = '预+治'
        }
        if (item.objective  == '3') {
          item.objective = '无指证'
        }
        newlist.push(item)
      }

      return newlist
    },

    getOpportunity() {
      if (this.Detail.opportunity == '0') {
        return '<30min'
      }
      if (this.Detail.opportunity  == '1') {
        return '30min≤and≤1h'
      }
      if (this.Detail.opportunity  == '2') {
        return '>1h'
      }
      if (this.Detail.opportunity  == '3') {
        return '未用'
      }
      return ''
    },
    getIncisionType() {
      if (this.Detail.incisionType == '0') {
        return 'I'
      }
      if (this.Detail.incisionType  == '1') {
        return 'II'
      }
      if (this.Detail.incisionType  == '2') {
        return 'III'
      }
      return ''
    },
    getIncisionHeal() {
      if (this.Detail.incisionHeal == '0') {
        return '甲'
      }
      if (this.Detail.incisionHeal  == '1') {
        return '乙'
      }
      if (this.Detail.incisionHeal  == '2') {
        return '丙'
      }
      return ''
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped></style>
